home *** CD-ROM | disk | FTP | other *** search
- #include "stdafx.h"
-
- cDisplayable::cDisplayable(cProperties *_orig)
- {
- if (_orig != 0)
- {
- orig = _orig;
-
- cmap = orig->cmap;
-
- circle_bounds = orig->circle;
- line_bounds = orig->line;
- }
- else
- {
- orig = 0;
-
- cmap = 0;
-
- line_bounds = 0;
- circle_bounds = 0;
- }
-
- image = 0;
- image_wait = 0;
-
- went_off_screen_horiz = FALSE;
- force_dirty = TRUE;
-
- rotation_angle = 0;
- scale = 1;
- }
-
- cDisplayable::~cDisplayable()
- {
- make_dirty();
- }
-
- void cDisplayable::update_image_variables()
- {
- if (image == 0)
- {
- x1 = x, y1 = y;
- x2 = x, y2 = y;
- }
- else
- {
- x1 = x - (int)(scale * image->origin_x);
- y1 = y + (int)(scale * image->origin_y);
-
- x2 = x1 + (int)(scale * bitmap->w) - 1;
- y2 = y1 - (int)(scale * bitmap->h) + 1;
- }
- }
-
- void cDisplayable::put_on_edge()
- {
- // Check sanity
-
- if (image == 0 || bitmap->w > surface->w - 2 * surface->edge)
- return;
-
- // Check if object is not on screen anymore
-
-
- if (x1 < surface->edge)
- {
- cPositionable::set_position(surface->edge + x - x1, y);
- update_image_variables();
-
- went_off_screen_horiz = TRUE;
- }
-
- else if (x2 > surface->w - surface->edge)
- {
- cPositionable::set_position(surface->w - surface->edge + x - x2, y);
- update_image_variables();
-
- went_off_screen_horiz = TRUE;
- }
-
- else
- {
- went_off_screen_horiz = FALSE;
- }
- }
-
- void cDisplayable::set_position(int _x, int _y)
- {
- cXPositionable::set_position(_x, _y);
- update_image_variables();
- put_on_edge();
- }
-
- void cDisplayable::set_position(fix _x, fix _y)
- {
- cXPositionable::set_position(_x, _y);
- update_image_variables();
- put_on_edge();
- }
-
- void cDisplayable::set_colormap(char *value)
- {
- if (cmap != value)
- {
- cmap = value;
-
- force_dirty = TRUE;
- }
- }
-
- void cDisplayable::set_rotation_angle(fix angle)
- {
- angle = -angle;
-
- if (angle != rotation_angle)
- {
- rotation_angle = angle;
-
- force_dirty = TRUE;
- }
- }
-
- void cDisplayable::set_scale(fix _scale)
- {
- ASSERT(_scale != (fix)0);
-
- if (scale != _scale)
- {
- scale = _scale;
- update_image_variables();
- put_on_edge();
-
- force_dirty = TRUE;
- }
- }
-
- void cDisplayable::set_image(cImage *_image)
- {
- // Check if there's change
-
- if (image == _image)
- return;
-
- // Set image
-
- image = _image;
-
- if (image != 0)
- {
- bitmap = image->bmp;
- image_wait = image->delay;
- }
-
- // Update variables that determine shape of image
-
- update_image_variables();
-
- // Make sure image is rewritten
-
- force_dirty = TRUE;
- }
-
- void cDisplayable::kill_image()
- {
- make_dirty();
-
- image = 0;
- update_image_variables();
- }
-
- void cDisplayable::write(int wx1, int wy1, int wx2, int wy2)
- {
- // Check sanity
-
- if (image == 0)
- return;
-
- // Get source and destination locations
-
- RECT sr;
-
- sr.left = x1 < wx1? wx1 - x1 : 0;
- sr.right = wx2 < x2? wx2 - x1 + 1 : (int)(scale * bitmap->w);
- sr.top = y1 > wy1? y1 - wy1 : 0;
- sr.bottom = wy2 > y2? y1 - wy2 + 1 : (int)(scale * bitmap->h);
-
- RECT tr;
-
- tr.left = surface->x_screen(x1 > wx1? x1 : wx1);
- tr.right = tr.left + sr.right - sr.left;
- tr.top = surface->y_screen(y1 < wy1? y1 : wy1);
- tr.bottom = tr.top + sr.bottom - sr.top;
-
- // Get the colormap
-
- char *cm = 0;
-
- if (image->cmap != 0)
- cm = image->cmap;
- else if (cmap != 0)
- cm = cmap;
-
- // Blit
-
- if (rotation_angle != (fix)0 || scale != (fix)1)
- {
- int mx = surface->x_screen((x1 + x2) / 2),
- my = surface->y_screen((y1 + y2) / 2);
-
- if (cm == 0)
- {
- switch(pixelformat.dwRGBBitCount)
- {
- case 8:
- rotated_blit(surface->dds, &tr, bitmap->dds, mx, my, rotation_angle, scale);
- break;
-
- case 16:
- rotated_blit16(surface->dds, &tr, bitmap->dds, mx, my, rotation_angle, scale);
- break;
-
- case 24:
- rotated_blit24(surface->dds, &tr, bitmap->dds, mx, my, rotation_angle, scale);
- break;
-
- case 32:
- rotated_blit32(surface->dds, &tr, bitmap->dds, mx, my, rotation_angle, scale);
- break;
- }
- }
- else
- {
- switch(pixelformat.dwRGBBitCount)
- {
- case 8:
- if (inawin)
- rotated_blit(surface->dds, &tr, bitmap->dds, mx, my, rotation_angle, scale);
- else
- rotated_colormapped_blit(surface->dds, &tr, bitmap->dds, mx, my, rotation_angle, scale, cm);
- break;
-
- case 16:
- rotated_blit16(surface->dds, &tr, bitmap->dds, mx, my, rotation_angle, scale);
- break;
-
- case 24:
- rotated_blit24(surface->dds, &tr, bitmap->dds, mx, my, rotation_angle, scale);
- break;
-
- case 32:
- rotated_blit32(surface->dds, &tr, bitmap->dds, mx, my, rotation_angle, scale);
- break;
- }
- }
- }
- else
- {
- if (cm != 0 && !inawin)
- {
- colormapped_blit(surface->dds, &tr, bitmap->dds, &sr, cm);
- }
- else
- {
- LPDIRECTDRAWSURFACE4 best = bitmap->bestptr(surface);
- while (!draw_ok(surface->dds->BltFast(tr.left, tr.top, best, &sr, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT)));
- }
- }
- }
-
- void cDisplayable::write_gravity()
- {
- // Check sanity
-
- if (image == 0 || image->gmap == 0)
- return;
-
- // Write gravity
-
- RECT r;
-
- r.left = GAME_X;
- r.right = GAME_X + GAME_DX;
- r.top = 0;
- r.bottom = GAME_DY;
-
- gravity_blit(backbuffer, &r, x - image->gmap[0] / 2, surface->start + surface->h - y - image->gmap[1] / 2, image->gmap);
- }